Overloading a Perl Operator
am 05.10.2011 23:40:06 von Phillip RichcreekI'm going to use a package called Data::Money in place of a similar
module that I had previously used but is no longer available for
downloading/ installing. Data::Money does everything that the other
package does (as far as the features that I am using), and it would
pretty much be a drop-in replacement but for one difference:
Data::Money does not overload the == and != but instead overloads the
<=> operator. So where I'm using " if ($a==$b)" and if($A!=$b)" a lot
of places, I'd have to change these to " if (! ($a<=>$b)) ?" some
places and "if($a<=>$b) ?" other places. I think I might also be using
some < and >, which would require way beyond just find and replace.
So...
This might be an opportunity to do some OO programming. Can someone
point me to basic documentation for writing code to overload an
operator in perl? Like, does it have to be in a "package"? Can I just
piggy-back it onto the Data::Money class? etc. No doubt this approach
will take 10 times the effort of just going in and brute force
changing my existing code, but this will be a lot more fun. Or not :-)
TIA,
Phil
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs